package cmj.cloudmusic.fragment.Discover;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.CBPageAdapter;
import com.bigkoo.convenientbanner.CBViewHolderCreator;
import com.bigkoo.convenientbanner.ConvenientBanner;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import cmj.cloudmusic.R;
import cmj.cloudmusic.UI.GridView2;
import cmj.cloudmusic.activity.Fragment_Activity;
import cmj.cloudmusic.adapter.gridview.DJ_baseAdapter;
import cmj.cloudmusic.adapter.gridview.MV_baseAdapter;
import cmj.cloudmusic.adapter.gridview.TJ_baseAdapter;
import cmj.cloudmusic.adapter.gridview.ZB_baseAdapter;
import cmj.cloudmusic.adapter.gridview.ZX_baseAdapter;
import cmj.cloudmusic.entity.MusicList;

/**
 * Created by 王虎 on 2016/12/11.
 */
public class D_gexingFragment extends Fragment implements View.OnClickListener {

    View view;
    Fragment_Activity context;

    ConvenientBanner banner;
    List<Integer> topImgList;
    int[] topImgs={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f};

    GridView2 gedan;
    GridView2 dujia;
    GridView2 newnew;
    GridView2 mv;
    GridView2 redio;

    Button srfm;
    LinearLayout mrgqtj;
    TextView date;
    Button bang;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context= (Fragment_Activity) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.d_gexing_fragment,null);
        initView();
        initGridView();
        initBanner();
        return view;
    }


    private void initView(){

        banner= (ConvenientBanner) view.findViewById(R.id.banner);

        gedan = (GridView2) view.findViewById(R.id.gedangridview);
        dujia = (GridView2) view.findViewById(R.id.dujiagridview);
        newnew = (GridView2) view.findViewById(R.id.newmusicgridview);
        mv = (GridView2) view.findViewById(R.id.mvgridview);
        redio = (GridView2) view.findViewById(R.id.dtgridview);

        srfm= (Button) view.findViewById(R.id.srfm);
        mrgqtj= (LinearLayout) view.findViewById(R.id.mrgqtj);
        date= (TextView) view.findViewById(R.id.date);
        bang= (Button) view.findViewById(R.id.bang);

        Calendar c=Calendar.getInstance();
        int day= c.get(Calendar.DAY_OF_MONTH);

        date.setText(day+"");

        srfm.setOnClickListener(this);
        mrgqtj.setOnClickListener(this);
        bang.setOnClickListener(this);
    }

    private void initGridView(){
        ArrayList<MusicList> list=new ArrayList<>();
        ArrayList<MusicList> list2=new ArrayList<>();
        ArrayList<MusicList> list3=new ArrayList<>();
        ArrayList<MusicList> list4=new ArrayList<>();
        ArrayList<MusicList> list5=new ArrayList<>();

        list.add(new MusicList(R.mipmap.move,30,"【经典电影】原声 回忆 | 飒飒"));
        list.add(new MusicList(R.mipmap.girl2,56,"每个人的心中都有一个小女孩"));
        list.add(new MusicList(R.mipmap.dongman,786,"冲击心灵的二次元天籁"));
        list.add(new MusicList(R.mipmap.girl4,232,"眉心一点朱砂红，浸染江山"));
        list.add(new MusicList(R.mipmap.zhaomin,442,"让他一声为你画眉"));
        list.add(new MusicList(R.mipmap.girl3,23122,"女生 | 古风 | 中国风"));
        list2.add(new MusicList(R.mipmap.zb5,"是不是你最爱的吴亦凡！"));
        list2.add(new MusicList(R.mipmap.zb6,"酒吧MC | 美女 电音"));
        list2.add(new MusicList(R.mipmap.zb3,"【经典】 深藏回忆深处的声音"));
        list2.add(new MusicList(R.mipmap.xiyou,"在我眼中，有千山万水，有全世界"));
        list3.add(new MusicList(R.mipmap.kiss,"大陆最新音乐","神秘的作者"));
        list3.add(new MusicList(R.mipmap.girl2,"大陆最新音乐","神秘的作者"));
        list3.add(new MusicList(R.mipmap.girl3,"大陆最新音乐","神秘的作者"));
        list3.add(new MusicList(R.mipmap.mouse,"大陆最新音乐","神秘的作者"));
        list3.add(new MusicList(R.mipmap.dongman,"大陆最新音乐","神秘的作者"));
        list3.add(new MusicList(R.mipmap.girl4,"大陆最新音乐","神秘的作者"));
        list4.add(new MusicList(R.mipmap.zb5,300,"地球上最火的MV","史上最牛的作者"));
        list4.add(new MusicList(R.mipmap.zb4,300,"地球上最火的MV","史上最牛的作者"));
        list4.add(new MusicList(R.mipmap.zb2,300,"地球上最火的MV","史上最牛的作者"));
        list4.add(new MusicList(R.mipmap.kiss,300,"地球上最火的MV","史上最牛的作者"));
        list5.add(new MusicList(R.mipmap.dt2,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));
        list5.add(new MusicList(R.mipmap.dt3,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));
        list5.add(new MusicList(R.mipmap.dt,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));
        list5.add(new MusicList(R.mipmap.zb2,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));
        list5.add(new MusicList(R.mipmap.dongman,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));
        list5.add(new MusicList(R.mipmap.zb6,"深夜话题，听妈妈的话。婆媳关系解密","脑子进水的主播"));

        TJ_baseAdapter adapter=new TJ_baseAdapter((Context) context,list);
        DJ_baseAdapter adapter2=new DJ_baseAdapter((Context) context,list2);
        ZX_baseAdapter adapter3=new ZX_baseAdapter((Context) context,list3);
        MV_baseAdapter adapter4=new MV_baseAdapter((Context) context,list4);
        ZB_baseAdapter adapter5=new ZB_baseAdapter((Context) context,list5);

        gedan.setAdapter(adapter);
        dujia.setAdapter(adapter2);
        newnew.setAdapter(adapter3);
        mv.setAdapter(adapter4);
        redio.setAdapter(adapter5);

    }

    private void initBanner() {
        topImgList=new ArrayList<>();
        if (topImgList.size() == 0) {
            for (int i = 0; i < topImgs.length; i++) {
                topImgList.add(topImgs[i]);
            }
        }
        banner.setPages(new CBViewHolderCreator<HolderView>() {
            @Override
            public HolderView createHolder() {
                return new HolderView();
            }
        }, topImgList)
                .setPointViewVisible(true)
                .setPageIndicator(new int[]{R.drawable.normal, R.drawable.check})
                .startTurning(3000)
                .setManualPageable(true);
        banner.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL);
    }

    /**
     * convientBanner holder
     */
    class HolderView implements CBPageAdapter.Holder<Integer> {

        private ImageView imageView;
        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, Integer data) {
            imageView.setImageResource(data);
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.srfm:
                Toast.makeText((Context) context,"攻城狮正在抢修中。。。", Toast.LENGTH_SHORT).show();
                break;
            case R.id.bang:
                Toast.makeText((Context) context,"攻城狮正在抢修中。。。", Toast.LENGTH_SHORT).show();
                break;
            case R.id.mrgqtj:
                context.replace("today");
                break;
        }
    }


}

